package com.huilan.hgt.util;


import com.huilan.hgt.exception.ExceptionEnum;

/**
 * @author ghy
 * @date 2018-06-07 15:44:49
 * @description restful api 统一返回数据模板
 */
public class ResponseResult {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private  Object result;


    public ResponseResult() {

    }


    public ResponseResult(ExceptionEnum exceptionEnum) {
        this.code = exceptionEnum.getCode();
        this.msg = exceptionEnum.getMsg();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    /**
     * 请求成功返回
     * @param object
     * @return
     */
    public static ResponseResult success(Object object){
        ResponseResult result=new ResponseResult();
        result.setCode(200);
        result.setMsg("请求成功");
        result.setResult(object);
        return result;
    }

    /**
     * 请求成功返回
     * @param object
     * @return
     */
    public static ResponseResult success(Object object,Class tClass){
        Object o = CopyListEntityUtil.po2dto(object,tClass);
        ResponseResult result=new ResponseResult();
        result.setCode(200);
        result.setMsg("请求成功");
        result.setResult(o);
        return result;
    }

    /**
     * 请求成功返回
     * @param code
     * @param msg
     * @param object
     * @return
     */
    public static ResponseResult success(int code, String msg, Object object){
        ResponseResult result=new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setResult(object);
        return result;
    }

    public static ResponseResult success(){
        return success(null);
    }

    /**
     * 请求失败返回
     * @param msg
     * @return
     */
    public static ResponseResult error(Integer code, String msg){
        ResponseResult result=new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

}
